<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获得表的元数据</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.pg-lo-write.html">« pg_lo_write</a></li>
      <li style="float: right;"><a href="function.pg-num-fields.html">pg_num_fields »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.pgsql.html">PostgreSQL 函数</a></li>
    <li>获得表的元数据</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.pg-meta-data" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">pg_meta_data</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_meta_data</span> &mdash; <span class="dc-title">
     获得表的元数据
    </span></p>

   </div>
 
 <div class="refsect1 description" id="refsect1-function.pg-meta-data-description">
  <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>pg_meta_data</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$table_name</code></span>): <span class="type">array</span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>pg_metadata()</strong></span> 以数组形式返回 <code class="literal">table_name</code> 表的定义。
    </p>
    <div class="warning"><strong class="warning">警告</strong><p class="simpara">此函数是<em class="emphasis">实验性</em>的。此函数的表象，包括名称及其相关文档都可能在未来的
PHP 发布版本中未通知就被修改。使用本函数风险自担。</p></div> 
   </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-meta-data-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">connection</code></dt>

     <dd>

      <p class="para">
       PostgreSQL database connection resource.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">table_name</code></dt>

     <dd>

      <p class="para">
       The name of the table.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-meta-data-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   以数组 <span class="type">array</span> 形式返回表的定义，如果出错则返回 <strong><code>false</code></strong>。
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.pg-meta-data-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1921">
    <p><strong>示例 #1 取得表的元数据</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$dbconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;</span><span style="color: #0000BB">$meta&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_meta_data</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'authors'</span><span style="color: #007700">);<br />&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$meta</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'&lt;pre&gt;'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$meta</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'&lt;/pre&gt;'</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(3) {
[&quot;author&quot;]=&gt;
array(5) {
  [&quot;num&quot;]=&gt;
  int(1)
  [&quot;type&quot;]=&gt;
  string(7) &quot;varchar&quot;
  [&quot;len&quot;]=&gt;
  int(-1)
  [&quot;not null&quot;]=&gt;
  bool(false)
  [&quot;has default&quot;]=&gt;
  bool(false)
}
[&quot;year&quot;]=&gt;
array(5) {
  [&quot;num&quot;]=&gt;
  int(2)
  [&quot;type&quot;]=&gt;
  string(4) &quot;int2&quot;
  [&quot;len&quot;]=&gt;
  int(2)
  [&quot;not null&quot;]=&gt;
  bool(false)
  [&quot;has default&quot;]=&gt;
  bool(false)
}
[&quot;title&quot;]=&gt;
array(5) {
  [&quot;num&quot;]=&gt;
  int(3)
  [&quot;type&quot;]=&gt;
  string(7) &quot;varchar&quot;
  [&quot;len&quot;]=&gt;
  int(-1)
  [&quot;not null&quot;]=&gt;
  bool(false)
  [&quot;has default&quot;]=&gt;
  bool(false)
}
}
</pre></div>
    </div>
   </div> 
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pg-meta-data-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.pg-convert.html" class="function" rel="rdfs-seeAlso">pg_convert()</a> - 将关联的数组值转换为适合 SQL 语句的格式。</span></li>
   </ul>
  </p>
 </div>

  </div></div></div></body></html>